//
//  CreateActiveHeaderView.m
//  Findif
//
//  Created by Mac on 2019/3/6.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "CreateActiveHeaderView.h"
#import "ZYBannerView.h"

@interface CreateActiveHeaderView ()<ZYBannerViewDataSource, ZYBannerViewDelegate>

@property (nonatomic, strong) ZYBannerView *banner;
@property (nonatomic, strong)NSArray * dataArray;

@end

@implementation CreateActiveHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


//- (void)setDataArray:(NSArray *)dataArray{
//
//    _dataArray = dataArray;
//
//    [self.banner reloadData];
//}


- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
    
    self.dataArray = [dict[@"merchants_goods_img"] componentsSeparatedByString:@","];
    
    [self.banner reloadData];
}


- (void)setModel:(GroupActiveModel *)model{
    
    _model = model;
    
    self.dataArray = [model.merchants_goods_img componentsSeparatedByString:@","];
    
    [self.banner reloadData];
}


- (void)setupUI{
    
    // 初始化
    self.banner = [[ZYBannerView alloc] init];
    self.banner.dataSource = self;
    self.banner.delegate = self;
    self.banner.shouldLoop = YES;
    self.banner.autoScroll = YES;
    //    self.banner.pageControlFrame = CGRectMake(200, 195, 45, 32);
    
    [self addSubview:self.banner];
    
    // 设置frame
    self.banner.frame = CGRectMake(0,0,kScreenW,200 * SCREENH6);
    
}


#pragma mark - ZYBannerViewDataSource
// 返回 Banner 需要显示 Item(View) 的个数
- (NSInteger)numberOfItemsInBanner:(ZYBannerView *)banner
{
    return self.dataArray.count;
}

// 返回 Banner 在不同的 index 所要显示的 View (可以是完全自定义的v iew, 且无需设置 frame)
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index
{
    
    NSString * imageName = self.dataArray[index];
    NSString * usrlStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,imageName];
    NSURL * url = [NSURL URLWithString:usrlStr];
    
    
    // 创建将要显示控件
    UIImageView *imageView = [[UIImageView alloc] init];
    //    imageView.image = [UIImage imageNamed:imageName];
    [imageView sd_setImageWithURL:url];
    //    [imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"轮播1"]];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    return imageView;
}

@end
